package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.AdminService;
import com.tarena.lbs.common.passport.encoder.JwtEncoder;
import com.tarena.lbs.common.passport.principle.UserPrinciple;
import com.tarena.lbs.pojo.basic.param.AdminParam;
import com.tarena.lbs.pojo.basic.param.UserParam;
import com.tarena.lbs.pojo.basic.po.AdminPO;
import com.tarena.lbs.pojo.basic.query.AdminQuery;
import com.tarena.lbs.pojo.basic.vo.AdminVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.print.attribute.standard.PageRanges;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class AdminController {
    //从请求头Authorization 解析jwt获取adminId 让业务查询数据
    @Autowired
    private JwtEncoder<UserPrinciple> jwtEncoder;
    @Autowired
    private AdminService adminService;
    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> adminDetail() throws BusinessException {
        AdminVO vo=adminService.adminDetail();
        return new Result<>(vo);
    }
    //后台查询已有的账号(包括平台管理员 商家账号)分页列表
    @PostMapping("/admin/basic/role/list")
    public Result<PageResult<AdminVO>> adminPage(@RequestBody AdminQuery query)
        throws BusinessException{
        PageResult<AdminVO> voPages=adminService.adminPage(query);
        return new Result<>(voPages);
    }
    //后台新增账号
    @PostMapping("/admin/basic/role/add")
    public Result<Void> adminSave(@RequestBody AdminParam param)
        throws BusinessException{
        adminService.adminSave(param);
        return Result.success();
    }
}









